package com.kedacom.ctsp.authority.vo;

import com.kedacom.ctsp.authority.entity.Area;
import com.kedacom.ctsp.authority.util.AuthorityTreeUtil;
import com.kedacom.ctsp.lang.Validate;
import com.kedacom.ctsp.lang.mapper.BeanMapperException;
import com.kedacom.ctsp.web.vo.AbstractTreeSortSupportVO;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * 区域
 *
 * @author
 */

@Data
@ApiModel
@Slf4j
public class SimpleAreaVo extends AbstractTreeSortSupportVO<Area, AreaVo, String> implements AreaVo {

    private String id;

    private String code;

    private String name;

    private String organ;

    private Double xMax;

    private Double xMin;

    private Double yMax;

    private Double yMin;

    private String path;

    /**
     * 拓展字段
     */
    private String extendedField;


    @Override
    public Area convertTo(Area area) throws BeanMapperException {
        super.convertTo(area);
        AuthorityTreeUtil.addParent(area, this);


        if (this.getParent() != null) {

            Validate.notNull(StringUtils.isBlank(this.getParent().getCode()) ? null : this.getParent().getCode(), "auth.dept.code.required");

            area.getParent().setCode(this.getParent().getCode());
        }
        return area;
    }
}
